﻿@page "{id:int}"
@model RazorPageSample.Pages.Blogs.EditModel
@{
    ViewData["Title"] = "Edit";
}
<script src="~/lib/jquery/dist/jquery.min.js"></script>
<h2>@ViewData["Title"]</h2>
<hr />
<form asp-page-handler="edit" method="post">
    @Html.AntiForgeryToken()
    <label asp-for="Blog.Name"></label>
    <input asp-for="Blog.Name" class="form-control" />
    <button type="submit" class="btn btn-primary">提交</button>
    <button type="button" class="btn btn-primary btn-edit">Ajax提交</button>
</form>
<script>
    $(function () {
        $('.btn-edit').on('click', function () {
            $.ajax({
                url: '/blogs/edit',
                type: 'post',
                data: $('form').serializeArray(),
                headers: {
                    "RequestVerificationToken":$('input:hidden[name="__requestVerificationToken"]').val()
                },
                success: function (data) {
                    console.log(data);
                }
            });
        });
    });
</script>